﻿using WSKnowledge.WSHelpers.DesignByContract;
using WSKnowledge.WSHelpers.Rules;

namespace WSKnowledge.WSHelpers.NHibernate
{
	public abstract class NamedEntityBase<TEntity> : EntityBase<TEntity>, INamedEntity<TEntity>
	{
		private string _name;
		private StringRule _rule = StringRule.CreateRule().WithLengthOf(50);

		public virtual string Name
		{
			get { return _name; }
			protected set
			{
				Check.Require(_rule.Validate(value), "Name is not valid");
				_name = value;
			}
		}

		protected NamedEntityBase()
		{
		}

		protected NamedEntityBase(string name)
		{
			Check.Require(_rule.Validate(name), "Name is not valid");
			_name = name;
		}
	}
}
